#! usr/bin/python

from core import objects as obj
import re


"""
C12.H14.O1.		6.0	174.1045	-104.5 mmu 
C9.H22.N2.O1.		0.0	174.1732	-173.2 mmu 
C10.H10.N2.O1.		7.0	174.0793	-79.3 mmu 
C7.H18.N4.O1.		1.0	174.1481	-148.1 mmu 
C8.H6.N4.O1.		8.0	174.0542	-54.2 mmu 
C5.H14.N6.O1.		2.0	174.1229	-122.9 mmu 
C6.H2.N6.O1.		9.0	174.0290	-29.0 mmu 
C10.H22.O2.		0.0	174.1620	-162.0 mmu 
C11.H10.O2.		7.0	174.0681	-68.1 mmu 
"""

class parser_H2:
	def __init__(self, H2file, mass):
		self.H2file =H2file
		self.mass = mass
		
		
	def parsing(self, alphabet):#
		#checking type of alphabet
		if not isinstance (alphabet, obj.Alphabet):
			raise TypeError, "Wrong type for alphabet", type(alphabet)
		formula = []
		#reg = re.compile('(.+)\t[2].+\n')
		with open(self.H2file) as f: #open(*******************************changes
			#elminiate wrong things
			for i in range (5):
				f.readline() #***added print
				
			#initialisation
			line =f.readline()
			while '\t' in line:#
				#starts filtering formulas
				formula.append(obj.Formula (line.split('\t')[0], self.mass, alphabet))#
				line=f.readline()	
			return formula
			#if reg.match(line):
				#print "line", line
				#print "matching",reg.match(line).group(1)
				
if __name__=="__main__":
	p =parser_H2 ("..\\160.txt")
	f = p.parsing(1)
	print len(f)
				
			
		
